package logic

import (
	"context"
	"shopping/model/mysql"

	"shopping/shoppingrpc/internal/svc"
	"shopping/shoppingrpc/shoppingrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShopAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShopAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShopAddLogic {
	return &ShopAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShopAddLogic) ShopAdd(in *shoppingrpc.ShopAddRequest) (*shoppingrpc.ShopAddResponse, error) {
	// todo: add your logic here and delete this line
	shop := mysql.Products{
		Image:      in.Image,
		Name:       in.Name,
		Navigation: in.Navigation,
		Label:      in.Label,
		Price:      float64(in.Price),
		Money:      float64(in.Money),
		Stock:      int(in.Stock),
		Sales:      int(in.Sales),
		Status:     in.Status,
	}
	mysql.DB.Debug().Create(&shop)
	return &shoppingrpc.ShopAddResponse{Id: int64(shop.ID)}, nil
}
